package es.abredatos.energyes

class ImportFilesJob {

	def dateService
	def dataService
	
	static triggers = {
		cron name: 'importFilesTrigger', startDelay:60000, cronExpression: '0 0 0 * * ?' //A la 00:00 de todos los días
//		cron name: 'importFilesTrigger', startDelay:60000, cronExpression: '0 * * * * ?' // Todos los minutos
	}

	def execute(){
		//	log.debug("Executing job ImportFiles...")
		
		def lastYear = dateService.findLastYearWithProductionItems() 
		def lastMonth = dateService.findLastMonthWithProductionItemsByYear(lastYear)
		def actualMonth = date[Calendar.MONTH]
		def actualYear = date[Calendar.YEAR]
		dataService.importDataForInterval([*lastYear..actualYear], [*lastMonth..actualMonth])
		//	log.debug("Job ended")
	}
}
